package com.example.ck.controller;


import com.example.ck.entity.Professional;
import com.example.ck.service.ProfessionalService;
import com.example.ck.vo.ResultVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 职称类型表
 * (Professional)表控制层
 *
 * @author makejava
 * @since 2024-05-01 12:14:44
 */
@Slf4j
@RestController
@CrossOrigin
@RequestMapping("professional")
public class ProfessionalController {
    @Autowired
    private ProfessionalService professionalService;

    /**
     * 查询职称类型表全部数据
     */
    @GetMapping
    public ResultVo findAllProfessional() {
        return new ResultVo(professionalService.queryAll());
    }

    /**
     * 添加职称类型
     */
    @PostMapping("/add")
    public ResultVo addProfessional(@RequestBody Professional professional) {
        boolean b = professionalService.addProfessional(professional);
        ResultVo vo = new ResultVo<>();
        if (b) {
            vo.setMessage("添加职称" + professional.getProfessional() + "成功");
            vo.setSuccess(true);
            vo.setCode(200);
            vo.setData(professional);
        } else {
            vo.setMessage("添加职称" + professional.getProfessional() + "失败");
            vo.setSuccess(false);
            vo.setCode(201);
        }
        return vo;
    }

    /**
     * 删除职称类型
     */
    @DeleteMapping("/delete")
    public ResultVo deleteProfessional(@RequestParam String professional) {
        boolean b = professionalService.deleteProfessional(professional);
        ResultVo vo = new ResultVo<>();
        if (b) {
            vo.setMessage("职称" + professional + "删除成功");
            vo.setSuccess(true);
            vo.setCode(200);
            vo.setData(professional);
        } else {
            vo.setMessage("职称" + professional + "删除失败");
            vo.setSuccess(false);
            vo.setCode(201);
        }
        return vo;
    }
}

